package cn.wx.read.neo4j.service;

import java.util.List;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import cn.wx.common.unitofwork.aop.UseUnitOfWork;
import cn.wx.read.neo4j.entity.Neo4jBook;
import cn.wx.read.neo4j.entity.Neo4jExpert;
import cn.wx.read.neo4j.entity.Neo4jPaper;
import cn.wx.read.neo4j.entity.Neo4jPatents;
import cn.wx.read.neo4j.entity.Relation;
import cn.wx.read.neo4j.repository.Neo4jBookRepository;
import cn.wx.read.neo4j.repository.Neo4jExpertRepository;
import cn.wx.read.neo4j.repository.Neo4jPaperRepository;
import cn.wx.read.neo4j.repository.Neo4jPatentsRepository;

/**
 * 导入数据
 */
@Service
@Transactional
public class Neo4jImportDataService {
	
	Logger logger = LoggerFactory.getLogger(Neo4jImportDataService.class);
	

	@Autowired
	Neo4jExpertRepository neo4jExpertRepository;

	@Autowired
	Neo4jBookRepository neo4jBookRepository;
	
	@Autowired
	Neo4jPaperRepository neo4jPaperRepository;
	
	@Autowired
	Neo4jPatentsRepository neo4jPatentsRepository;
	
	
	
	/**
	 * 批量导入专家
	 */
	@UseUnitOfWork(saga = "BetchNeo4jExpert")
	public void importBetchExpert(List<Neo4jExpert> nes){
		if(nes == null || nes.size() == 0){
			return;
		}
		neo4jExpertRepository.saveBetch(nes);
	}
	
	/**
	 * 批量导入图书
	 */
	@UseUnitOfWork(saga = "BetchNeo4jBook")
	public void importBetchBook(List<Neo4jBook> nes){
		if(nes == null || nes.size() == 0){
			return;
		}
		neo4jBookRepository.saveBetch(nes);
	}
	
	/**
	 * 批量导入论文
	 */
	@UseUnitOfWork(saga = "BetchNeo4jPaper")
	public void importBetchPaper(List<Neo4jPaper> nes){
		if(nes == null || nes.size() == 0){
			return;
		}
		neo4jPaperRepository.saveBetch(nes);
	}
	
	/**
	 * 批量导入专利
	 */
	@UseUnitOfWork(saga = "BetchNeo4jPatents")
	public void importBetchPatents(List<Neo4jPatents> nes){
		if(nes == null || nes.size() == 0){
			return;
		}
		neo4jPatentsRepository.saveBetch(nes);
	}
	
	/**
	 * 批量导入专家和图书关系
	 */
	@UseUnitOfWork(saga = "BetchNeo4jRelationEb")
	public void importBetchRelationEb(List<Relation> nes){
		if(nes == null || nes.size() == 0){
			return;
		}
		neo4jExpertRepository.saveBetchRelationBook(nes);
	}
	
	
	/**
	 * 批量导入专家和论文的关系
	 */
	@UseUnitOfWork(saga = "BetchNeo4jRelationEp")
	public void importBetchRelationEp(List<Relation> nes){
		if(nes == null || nes.size() == 0){
			return;
		}
		neo4jExpertRepository.saveBetchRelationPaper(nes);
	}
	
	/**
	 * 批量导入专家和专利关系
	 */
	@UseUnitOfWork(saga = "BetchNeo4jRelationEpt")
	public void importBetchRelationEpt(List<Relation> nes){
		if(nes == null || nes.size() == 0){
			return;
		}
		neo4jExpertRepository.saveBetchRelationPatents(nes);
	}
	
	/**
	 * 批量导入专家和领域关系
	 * 作为节点保存
	 */
	@UseUnitOfWork(saga = "BetchNeo4jRelationEfo")
	public void importBetchRelationEfo(List<Relation> nes){
		if(nes == null || nes.size() == 0){
			return;
		}
		neo4jExpertRepository.saveBetchRelationField(nes);
	}
	
	/**
	 * 批量导入专家和领域关系论文数PaperCount
	 * 作为节点保存
	 */
	@UseUnitOfWork(saga = "BetchNeo4jRelationEfoPaperCount")
	public void importBetchRelationEfoPaperCount(List<Relation> nes){
		if(nes == null || nes.size() == 0){
			return;
		}
		neo4jExpertRepository.saveBetchRelationFieldPaperCount(nes);
	}
	
	
	/**
	 * 批量导入专家和领域关系Rank
	 * 作为节点保存
	 */
	@UseUnitOfWork(saga = "BetchNeo4jRelationEfoRank")
	public void importBetchRelationEfoRank(List<Relation> nes){
		if(nes == null || nes.size() == 0){
			return;
		}
		neo4jExpertRepository.saveBetchRelationFieldRank(nes);
	}
	
	
	/**
	 * 批量导入专家和领域关系
	 * 作为节点保存
	 */
	@UseUnitOfWork(saga = "BetchNeo4jRelationEor")
	public void importBetchRelationEor(List<Relation> nes){
		if(nes == null || nes.size() == 0){
			return;
		}
		neo4jExpertRepository.saveBetchRelationOrg(nes);
	}
	
}
